#include <bits\stdc++.h>
using namespace std;

class Solution {
    class Compare {
    public:
        bool operator()(vector<int>& a, vector<int>& b) {
            return a[0] < b[0];
        }
    };
public:
    int findLongestChain(vector<vector<int>>& pairs) {
        int n = pairs.size();
        vector<int> dp(n, 1);
        sort(pairs.begin(), pairs.end(), Compare());
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (pairs[i][0] > pairs[j][1]) {
                    dp[i] = max(dp[i], dp[j] + 1);
                }
            }
        }
        return *max_element(dp.begin(), dp.end());
    }
};